package com.example.newsapp.view.activity;

import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.newsapp.R;

public class NewsDetailActivity extends AppCompatActivity {
    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_detail);

        String url = getIntent().getStringExtra("url");
        String title = getIntent().getStringExtra("title");

        // 设置标题
        setTitle(title);

        webView = findViewById(R.id.webView);
        // 启用JavaScript
        webView.getSettings().setJavaScriptEnabled(true);
        // 设置WebViewClient以在WebView内加载页面
        webView.setWebViewClient(new WebViewClient());

        if (url != null) {
            webView.loadUrl(url);
        } else {
            Toast.makeText(this, "加载失败", Toast.LENGTH_SHORT).show();
            finish();
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }
    //禁止网页返回
//    @Override
//    public void onBackPressed() {
//        if (webView.canGoBack()) {
//            webView.goBack();
//        } else {
//            super.onBackPressed();
//        }
//    }
}